﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Reflection;
using Cofe.Core;
using Cofe.Core.Utils;

namespace Cofe.Web
{
    /// <summary>
    /// Provide a list of XName for used in xml serialization and deserialization.
    /// </summary>
    public static class XNames
    {
        /// <summary>
        /// Return all XName in this XNames class
        /// </summary>
        /// <returns></returns>
        public static XName[] GetAllXNames()
        {
            List<XName> retVal = new List<XName>();
            Type type = typeof(XNames);
            foreach (var prop in type.GetFields())
                if (prop.GetValue(null).GetType() == typeof(XName))
                    retVal.Add(prop.GetValue(null) as XName);
            return retVal.ToArray();
        }



        #region Entry related.
        #region Elements
        /// <summary>
        /// Represents a link.
        /// </summary>
        public static XName Link = XName.Get("Link", CofeConstants.Namespace);

        /// <summary>
        /// Represents a list of Link(s) 
        /// </summary>
        public static XName Links = XName.Get("Links", CofeConstants.Namespace);

        /// <summary>
        /// Represent an entry.
        /// </summary>
        public static XName Entry = XName.Get("Entry", CofeConstants.Namespace);

        /// <summary>
        /// Represent LastWriteTime of en entry.
        /// </summary>
        public static XName Time = XName.Get("Time", CofeConstants.Namespace);

        public static XName Size = XName.Get("Size", CofeConstants.Namespace);

        /// <summary>
        /// Represent information related to an entry.
        /// </summary>
        public static XName EntryType = XName.Get("EntryType", CofeConstants.Namespace);

        /// <summary>
        /// Represent a list of Entry(s).
        /// </summary>
        public static XName Entries = XName.Get("Entries", CofeConstants.Namespace);

        /// <summary>
        /// Root tag for Metadata.
        /// </summary>
        public static XName Metadata = XName.Get("Metadata", CofeConstants.Namespace);

        /// <summary>
        /// Root tag for ResourceList.
        /// </summary>
        public static XName ResourceList = XName.Get("Resources", CofeConstants.Namespace);

        /// <summary>
        /// Root tag for EntryList, which contain (Entries).
        /// </summary>
        public static XName List = XName.Get("List", CofeConstants.Namespace);

        /// <summary>
        /// Root tag for Search.
        /// </summary>
        public static XName Search = XName.Get("Search", CofeConstants.Namespace);
        #endregion

        #region Attributes

        /// <summary>
        /// Text representation of an EntryType
        /// </summary>
        public static XName Description = XName.Get("Description", "");

        /// <summary>
        /// Media Type of a Link
        /// </summary>
        public static XName MediaType = XName.Get("MediaType", "");

        /// <summary>
        /// Relation Type of a Link, related to current entry or search.
        /// </summary>
        public static XName RelationType = XName.Get("Rel", "");

        /// <summary>
        /// Type of an Entry (File, Folder)
        /// </summary>
        public static XName EntryBaseType = XName.Get("BaseType", "");

        /// <summary>
        /// Uri of the current Link.
        /// </summary>
        public static XName Uri = XName.Get("Uri", "");

        /// <summary>
        /// Id of the current Entry, Event or Search.
        /// </summary>
        public static XName ID = XName.Get("ID", CofeConstants.Namespace);

        /// <summary>
        /// Name of the current EntryList.
        /// </summary>
        public static XName Name = XName.Get("Name", CofeConstants.Namespace);

        /// <summary>
        /// Type of the current EntryList/EventList/Event (Auto/Custom/Xml)
        /// </summary>
        public static XName Type = XName.Get("Type", CofeConstants.Namespace);

        /// <summary>
        /// Entry list parameter.
        /// </summary>
        public static XName Parameter = XName.Get("Parameter", CofeConstants.Namespace);

        /// <summary>
        /// Path of the current Entry (entry path) or search (lookup path).
        /// </summary>
        public static XName Path = XName.Get("Path", CofeConstants.Namespace);

        /// <summary>
        /// IncludeFiles of the current Search.
        /// </summary>
        public static XName IncludeFiles = XName.Get("IncludeFiles", "");

        /// <summary>
        /// IncludeFolders of the current Search.
        /// </summary>
        public static XName IncludeFolders = XName.Get("IncludeFolders", "");

        /// <summary>
        /// Status of the current search.
        /// </summary>
        public static XName StatusType = XName.Get("Status");

        /// <summary>
        /// Mask of the current search.
        /// </summary>
        public static XName Mask = XName.Get("Masks");
        #endregion
        #endregion

        #region User related
        #region Elements

        /// <summary>
        /// Represents a Volume.
        /// </summary>
        public static XName VolumeInfo = XName.Get("VolumeInfo", CofeConstants.Namespace);

        #endregion

        #region Attributes

        /// <summary>
        /// Volume key
        /// </summary>
        public static XName VolumeId = XName.Get("VolumeId", "");

        /// <summary>
        /// Factory key of a volume.
        /// </summary>
        public static XName FactoryId = XName.Get("FactoryId", "");

        /// <summary>
        /// Parameters used to construct a volume.
        /// </summary>
        public static XName ConstructParam = XName.Get("ConstructParam", "");

        /// <summary>
        /// Access mode of a Volume (None, Read, Write, Execute, All).
        /// </summary>
        public static XName VolumeAccessMode = XName.Get("VolumeAccessMode", "");

        #endregion

        #endregion

        #region Event related

        #region Elements
        /// <summary>
        /// Represents an Event.
        /// </summary>
        public static XName Event = XName.Get("Event", CofeConstants.Namespace);

        /// <summary>
        /// Represents a list of Events.
        /// </summary>
        public static XName Events = XName.Get("Events", CofeConstants.Namespace);

        #endregion

        #endregion
    }
}
